package mysql

import "gorm.io/gorm"

type Users struct {
	gorm.Model
	Tel      string `json:"tel" gorm:"char(11);not null;unique;comment:'手机号'"`
	Password string `json:"password" gorm:"char(32);not null;comment:'密码'"`
	Cookie   int    `json:"cookie" gorm:"tinyint(1);not null;comment:'1-正常2-非正常'"`
}

func (u *Users) Register() error {
	return DB.Model(&Users{}).Create(&u).Error
}

func FindUser(tel string) (user *Users) {
	DB.Model(&Users{}).Where("tel=?", tel).Limit(1).Find(&user)
	return
}

func Update(password string, id int) error {
	return DB.Model(&Users{}).Where("id=?", id).Update("password", password).Error
}
